<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>

  <body>
    <textarea name="" id="text" cols="30" rows="10"></textarea
    ><button>提交</button>
    <div></div>
    <script>
      // 传统方式
      var name = "tommibaby";
      var newName = name.replace("tom", "jim");
      console.log(name);
      console.log(newName);

      // 正则表达式方式----字符串.replace(/xxx/,"xxx")
      // 注意：正则表达式最后跟上g表示全部匹配，i表示忽略大小写
      var text = document.querySelector("#text");
      var btn = document.querySelector("button");
      var div = document.querySelector("div");
      btn.onclick = function () {
        div.innerHTML = text.value.replace(/fuck|激情/gi, "**");
      };
    </script>
  </body>
</html>
